package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.customer.domain.InsuranceCompany;
import com.ktgj.customer.service.IInsuranceCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 保险公司
Controller
 * 
 * @author ruoyi
 * @date 2021-07-27
 */
@ControllerAdvice
@RestController
@RequestMapping("/company")
public class InsuranceCompanyController extends BaseController
{
    @Autowired
    private IInsuranceCompanyService insuranceCompanyService;

    /**
     * 查询保险公司
列表
     */
    @PreAuthorize(hasPermi = "system:company:list")
    @GetMapping("/list")
    public TableDataInfo list(InsuranceCompany insuranceCompany)
    {
        startPage();
        List<InsuranceCompany> list = insuranceCompanyService.selectInsuranceCompanyList(insuranceCompany);
        return getDataTable(list);
    }

    /**
     * 导出保险公司
列表
     */
    @PreAuthorize(hasPermi = "system:company:export")
    @Log(title = "保险公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InsuranceCompany insuranceCompany) throws IOException
    {
        List<InsuranceCompany> list = insuranceCompanyService.selectInsuranceCompanyList(insuranceCompany);
        ExcelUtil<InsuranceCompany> util = new ExcelUtil<InsuranceCompany>(InsuranceCompany.class);
        util.exportExcel(response, list, "保险公司数据");
    }

    /**
     * 获取保险公司
详细信息
     */
    @PreAuthorize(hasPermi = "system:company:query")
    @GetMapping(value = "/{insCoId}")
    public AjaxResult getInfo(@PathVariable("insCoId") Long insCoId)
    {
        return AjaxResult.success(insuranceCompanyService.selectInsuranceCompanyById(insCoId));
    }

    /**
     * 新增保险公司

     */
    @PreAuthorize(hasPermi = "system:company:add")
    @Log(title = "保险公司", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsuranceCompany insuranceCompany)
    {
        return toAjax(insuranceCompanyService.insertInsuranceCompany(insuranceCompany));
    }

    /**
     * 修改保险公司

     */
    @PreAuthorize(hasPermi = "system:company:edit")
    @Log(title = "保险公司", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsuranceCompany insuranceCompany)
    {
        return toAjax(insuranceCompanyService.updateInsuranceCompany(insuranceCompany));
    }

    /**
     * 删除保险公司

     */
    @PreAuthorize(hasPermi = "system:company:remove")
    @Log(title = "保险公司", businessType = BusinessType.DELETE)
	@DeleteMapping("/{insCoIds}")
    public AjaxResult remove(@PathVariable Long[] insCoIds)
    {
        return toAjax(insuranceCompanyService.deleteInsuranceCompanyByIds(insCoIds));
    }

    /**
     * 保险公司列表
     * */
    @PostMapping("/insuranceCompanyList")
    public AjaxResult insuranceCompanyList(){
        List<InsuranceCompany> insuranceCompanies = insuranceCompanyService.insuranceCompanyList();
        return AjaxResult.success(insuranceCompanies);
    }
}
